import requests
import  os

DOWNLOAD_DIR= 'D:/tttt'
def download_video_content() -> None:
    """
    下载视频内容并保存到本地。
    
    Args:
        video_url (str): 视频下载的 URL。
        title (str): 视频的标题，用于命名文件。
        headers (Dict[str, str]): HTTP 请求头，包含 Cookie、User-Agent 和 Referer。

    """
    video_url='https://www.tiktok.com/aweme/v1/play/?faid=1988&file_id=b75883da42a84e4599fcca28ff6ccf0a&is_play_url=1&item_id=7443893844870974738&line=0&ply_type=2&redirect=0&signaturev3=dmlkZW9faWQ7ZmlsZV9pZDtpdGVtX2lkLmZhNTNkM2M4MWE3MjE3ZTRlZTU2OWUxNTgzZTBmMGM1&tk=tt_chain_token&video_id=v10044g50000ct70bvvog65lgc8bl8h0'
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36',
        'Referer': 'https://www.tiktok.com/',
        'Host':'v16-webapp-prime.tiktok.com',
        'Cookie':'passport_csrf_token=46e6d9bbb016fe403d87112cb8389574; passport_csrf_token_default=46e6d9bbb016fe403d87112cb8389574; store-country-code-src=uid; _ttp=2pbse3RL5uUMBofxuEnWJ9iXB5r; tta_attr_id_mirror=0.1733046246.7443376950325805073; multi_sids=7443376039546700856%3Ae1519faea81a64b7bdcdc731e0766d41; cmpl_token=AgQQAPPdF-RO0rdywbW25x0B_S3Qwy0bf6jZYNsl8A; passport_auth_status=188162ccad337b2a97aaae6baaa2dafe%2Cc5c33ff566b54c113d518d1594ce275d; passport_auth_status_ss=188162ccad337b2a97aaae6baaa2dafe%2Cc5c33ff566b54c113d518d1594ce275d; uid_tt=b00d73c730081213c9695f021b3c9a2d98f00297e1a0274d4bbb2b76277c39be; uid_tt_ss=b00d73c730081213c9695f021b3c9a2d98f00297e1a0274d4bbb2b76277c39be; sid_tt=e1519faea81a64b7bdcdc731e0766d41; sessionid=e1519faea81a64b7bdcdc731e0766d41; sessionid_ss=e1519faea81a64b7bdcdc731e0766d41; store-idc=alisg; store-country-code=hk; tt-target-idc=alisg; tt-target-idc-sign=nfMSdV5sHFWhCanrbdv6Hc2RXecYtls6FqgEonB-F3MoQKlC6gOO08xrk4P0y34Wboqzzg6n4ezMDMN55IVacuClr0YnQ7RcWuob8mdnsOTL481fQdl7hNfRFJNMyl5iWoWNU3xwyZkVgkHmc_eC0oPwt8Wcbv6jCwJBcn0nvXp7LksofDdZLMr9rbc_YsvfC4jd_qgb7iTBgCNpnafgf6jJtFpyAmUyf8ayU15fg-dvcY_mcDVyMfEywGQAPKe2C3GICBpn8LTKcQd8d0baot6w_A-bTvJRUrkbcDL24GmbCCbVJiRIh0ebdu0_LiW5GCrr-VpTk-CDB1fknJQuqfN7_1d4puMO65-NJYQzWY_ptED1YkMoV4f_cIHxlBiErZwTXVUKYcYWr2lTXWtelwKVeRfbnCKJPQSVehxLjIsRaKv0Z3NUfNiz0rUlAJ_RHzaq2ptK1Eqf3ibhzohmRlszxB3Crsjwa9-AJpsPCHkRNYcl8dOOAbf7b5kMDZex; sid_guard=e1519faea81a64b7bdcdc731e0766d41%7C1733053713%7C15551985%7CFri%2C+30-May-2025+11%3A48%3A18+GMT; sid_ucp_v1=1.0.0-KDE4Njc4YTk4NDljMjBiNDliMjBhOWE3MDUwM2MyZGU5NTg1YTg2NzQKGQi4iNf2o-KLpmcQkZqxugYYsws4CEASSAQQAxoCbXkiIGUxNTE5ZmFlYTgxYTY0YjdiZGNkYzczMWUwNzY2ZDQx; ssid_ucp_v1=1.0.0-KDE4Njc4YTk4NDljMjBiNDliMjBhOWE3MDUwM2MyZGU5NTg1YTg2NzQKGQi4iNf2o-KLpmcQkZqxugYYsws4CEASSAQQAxoCbXkiIGUxNTE5ZmFlYTgxYTY0YjdiZGNkYzczMWUwNzY2ZDQx; tt_chain_token=XMjL3vp7VscDTxYdjyijkA==; odin_tt=c8584f04addd3af6f6d0d3fd08612bcd2dc796914e843849ce870e702e1f38f51f5d5a536c905a8e40c3f1f2ff1b16e5071918addb4f123e49bf2a6fd3deb357ab20e8a62ea98829fdb7f68a34bc86f5; tt_csrf_token=CDnIA8UL-8lBvf68LgmbZ7uWkW6XDHyw_pvk; ak_bmsc=06426FF52B95DAD8747F91C9071B9CB7~000000000000000000000000000000~YAAQLqvOF+0426mTAQAAmTWIqxogakic/V4hZz1QAt9uJBPgc2pxIYbnLVnj5g/hMcaj9qvsrehjgN6mKJGdranU1iT4TOMg7enqleFu/8ti/l8ryv7DRjawbOVC/HHTCTW+dJNiUYHPNs9nfbWLDuyu0dpwN+t3vwX+9rotGo5/QYEXN4IOEDh+an5erU+wA0PO0Rdd+WF/xx7qVYcytb4x6a4hsw/wYV5GApAEpkZi+NCMNcvF4k+K2V2cQ8xvByDYX9FVN4PCHPOG+cDlcVEOC/tBk42BAVvdK3XDGT31nrvAF1EAzke32abs0b+tUlyzk7GKFe7Yz9y8cPZrEmJ36IUIDE+fymLN; ttwid=1%7CRE7xZ5mx-YeDgXy-5R0-0iWV8ALPQ9EtTYXRvBnJ3KU%7C1733749652%7C5629e0b894439c2a97361840a449b3ad72934422b30289c6ff9dc22027745a60; bm_sv=582E1980B0C829FD5D3B73A244B7CB54~YAAQJKvOF4RacJKTAQAAJGONqxpInmuGDA1slDIwqnmE7HSOJONN+2k6FcuXa7cifUuO8Y912aw+NGFExmGjDCYD5jIkTKrNLLS3T21wU5ZAzQsmVls4LkNw8hAs8sZuHU3qsElY9wj47KQ+/I6WIpj/OpMoOjbGE0FWIM1xGceCxCFXTlSeh71f12hYbMiPsvAS5bq8omPbMY+WqpARd4XgB4ZolOGHI1XCA0ALlPpkRscku00PFLNCyy85BISo~1; msToken=E97MYerZ6CfvORtE-f6G1rAawP1yF7YTFqP7ZYNoz0_3Mc5F4hKday3muis8VtmiQV19s7lcrNbAMnIA1TpdRoDZknchp1T6swBH9dBy1Csa0XjNKUz7r02zM5odNfRK9jYBZ28j6u83Pw=='
    }
    proxy = {
            'http': 'http://127.0.0.1:8888',
            'https': 'http://127.0.0.1:8888',
        }
    try:
        response = requests.get(video_url, timeout=10,headers=headers,proxies=proxy,verify=False)
        # print(response.content)
        response.raise_for_status()
        file_path = os.path.join(DOWNLOAD_DIR, '2.mp4')
        with open(file_path, 'wb') as f:
            f.write(response.content)
        print(f"已下载并保存视频: {file_path}")
    except requests.RequestException as e:
        print(f"下载视频失败: {e}")
    except Exception as e:
        print(f"保存视频时发生错误: {e}")

if __name__ == "__main__":
    download_video_content()